package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.smartdor.entity.SdAttenceTrackRecord;
import cn.sdormitory.smartdor.service.SdAttenceTrackRecordService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lx
 * @date: 2023/10/7 14:35
 * @description:
 */

@RestController
@Api(tags = "Smartdor-sdAttence-trackRecord=> 宿舍考勤管理")
@RequestMapping("/app/sdAttence/trackRecord")
public class AppSdAttenceTrackRecordController {

    @Autowired
    private SdAttenceTrackRecordService trackRecordService;

    @PostMapping("/create")
    public CommonResult create(@RequestBody SdAttenceTrackRecord trackRecord){
        int count = trackRecordService.create(trackRecord);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @GetMapping("/getTrackRecordByDateAndStuId")
    public CommonResult getTrackRecordByDateAndStuId(@RequestParam String contactDate, Long studentId){
        List<SdAttenceTrackRecord> records = trackRecordService.getTrackRecordByDateAndStuId(contactDate,studentId);
        return CommonResult.success(records);
    }

    @PostMapping("/update")
    public CommonResult update(@RequestBody SdAttenceTrackRecord trackRecord){
        int count = trackRecordService.update(trackRecord);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
